// pages/serve/study/study.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bar_Height: wx.getSystemInfoSync().statusBarHeight + 45,
    title_study:"1",
  },
  //科目选择
  studyTitle(e){
    var that = this
    // if (e.currentTarget.dataset.index == 1){
    app.titleStudy = e.currentTarget.dataset.index
      that.setData({
        title_study: e.currentTarget.dataset.index
      })
    // accuracy(that, e.currentTarget.dataset.index,2)
    // }
  },
  //排行榜
  ranking(e){
    wx.navigateTo({
      url: '/pages/serve/ranking/ranking',
    })
  },
  //安全视频
  safety(e){
    wx.navigateTo({
      url: '/pages/serve/safety/safety',
    })
  },
  //练题
  chapterClcik(e){
    var that = this
    console.log(e.currentTarget.dataset.chapter, that.data.title_study, that.data.cardType)
    app.chapterStudy = e.currentTarget.dataset.chapter
    wx.navigateTo({
      url: '/pages/serve/chapter/chapter',
    })
    // wx.navigateTo({
    //   url: '/pages/serve/chapter/chapter?type=' + that.data.cardType + "&title=" + that.data.title_study + "&chapter=" + e.currentTarget.dataset.chapter,
    // })
  },
  //难题解析
  problemClcik(e){
    wx.navigateTo({
      url: '/pages/serve/problem/problem',
    })
  },
  //我的错题
  problemClcik2(e) {
    wx.navigateTo({
      url: '/pages/serve/practice/practice',
    })
  },
  // 分类练习
  chapterClcik2(e){
    var that = this
    console.log(e.currentTarget.dataset.chapter, that.data.title_study, that.data.cardType)
    app.chapterStudy = e.currentTarget.dataset.chapter
    wx.navigateTo({
      url: '/pages/serve/section/section',
    })
  },
  //模拟考试
  examClick(e){
    wx.navigateTo({
      url: '/pages/serve/exam/exam',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.titleStudy = 1
    // console.log(app.cardType, app.titleStudy)
    var that = this
    // accuracy(that,1,2)

    let cards;
    if (app.cardType == 1){
      cards = "小车"
    }
    if (app.cardType == 2) {
      cards = "货车"
    }
    if (app.cardType == 3) {
      cards = "客车"
    }
    that.setData({
      cards: cards,
      cardType: app.cardType
    })
  },
  backServe(e){
    wx.switchTab({
      url: '/pages/serve/serve',
    })
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideShareMenu()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // accuracy(this, this.data.title_study,1)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})

//获取顺章练习正确率
function accuracy(that, course,num) {
  // console.log(course, car_status, "gdashjgdshja")
  wx.request({
    url: 'https://minitest.17jxyx.com/api/v1/subject/correctness',
    method: "POST",
    header: {
      token: app.token
    },
    data:{
      course: course,
      car_status: app.cardType
    },

    success: function (res) {
      console.log(res)
      let obj = {}
      if (num == 1) {
        wx.hideNavigationBarLoading() //完成停止加载
        wx.stopPullDownRefresh() //停止下拉刷新
      }
      if(res.data > 1){
        obj.num = res.data
      }else{
        obj.probability = res.data

      }
      console.log(obj)
      that.setData({
        obj:obj
      })
      // if (res.data.length > 0) {
      //   dispose(that, res)
      // }
    },
    fail: function (res) {
      console.log(res)
    }
  })
}